package com.design.mode.observer;

import java.util.ArrayList;
import java.util.List;

/**
 * 描述:
 * 被观察者实现
 *
 * @author luzhongfu
 * @create 2018-12-23 3:06 PM
 */
public class WebchartServer implements Observerable {

    private List<Observer> list;

    private String message;

    public WebchartServer() {
        list = new ArrayList<Observer>();
    }

    public void registerObserver(Observer o) {
        list.add(o);
    }

    public void removeObserver(Observer o) {
        list.remove(o);
    }

    public void notifyObserver() {
        list.forEach(info->info.update(message));
    }

    public void setInformation(String message){
        this.message = message;
        System.out.println("微信服务更新消息： " + message);
        //消息更新，通知所有观察者
        notifyObserver();
    }
}
